Imports MindFusion.Diagramming
Imports MindFusion.Drawing

Public Class ClsMMTableNode
    Inherits TableNode
    'represents my own diagram tablenode

#Region "Attributes"
#Region "Private attributes"
    Private MiID As Integer = -1 'KROSLIB ID for this node. ID identifies this node, it is the same ID as in KrosLib - useful during synchroselection in compare version mode
    Private MsAppTableName As String = "" 'AppTableName from aMod DS = programmatic table name. Coz Me.Caption = HumanTableName = analytic table name
    Private MbHasRTFnote As Boolean = False 'table RTF note indicator
#End Region
#End Region
#Region "Constructors"
    Public Sub New()
        MyBase.new()
        MMSetDefaultProperties()
    End Sub

    Public Sub New(ByVal IiID As Integer)
        MyBase.new()
        MMSetDefaultProperties()
        MiID = IiID
    End Sub

    Public Sub New(ByVal parent As MindFusion.Diagramming.Diagram)
        MyBase.New(parent)
        MMSetDefaultProperties()
    End Sub

    Protected Sub New(ByVal prototype As MindFusion.Diagramming.DiagramItem)
        MyBase.New(prototype)
    End Sub

    Protected Sub New(ByVal prototype As MindFusion.Diagramming.DiagramNode)
        MyBase.New(prototype)
    End Sub

    Public Sub New(ByVal prototype As MindFusion.Diagramming.TableNode)
        MyBase.New(prototype)
    End Sub

    Public Sub New(ByVal IiX As Integer, ByVal IiY As Integer, ByVal IiWidth As Integer, ByVal IiHeight As Integer)
        MyBase.New()
        MMSetDefaultProperties()
        MyBase.Bounds = SDRectangleVirginCreator(IiX, IiY, IiWidth, IiHeight)
    End Sub
#End Region
#Region "Properties"
#Region "Public attributes"
    'Public ReadOnly Property MMRectangleForNewLink() As RectangleF
    '    Get
    '        Return SDRectangleFVirginCreator(Me.Bounds.Right - 12, Me.Bounds.Top + 2, 10, Me.CaptionHeight - 2)
    '    End Get
    'End Property
    Public Property AppTableName() As String
        Get
            Return MsAppTableName
        End Get
        Set(ByVal IsValue As String)
            MsAppTableName = IsValue
        End Set
    End Property
    Public Property HasRTFnote() As Boolean
        Get
            Return MbHasRTFnote
        End Get
        Set(ByVal IbValue As Boolean)
            MbHasRTFnote = IbValue
        End Set
    End Property
    Public Property ID() As Integer
        Get
            Return MiID
        End Get
        Set(ByVal IiValue As Integer)
            MiID = IiValue
        End Set
    End Property
#End Region
#End Region
#Region "Subs"
#Region "Overrides & Overloads Subs"
    'overrided sub for saving to XML
    Protected Overrides Sub SaveToXml(ByVal xmlElement As System.Xml.XmlElement, ByVal context As MindFusion.Diagramming.XmlPersistContext)
        MyBase.SaveToXml(xmlElement, context)
        context.WriteString(CStr(MiID), "ID", xmlElement)
        context.WriteString(MsAppTableName, "AppTableName", xmlElement)
        context.WriteString(IIf(MbHasRTFnote, "TRUE", "FALSE"), "HasRTFnote", xmlElement)
    End Sub
    'overrided sub for loading from XML
    Protected Overrides Sub LoadFromXml(ByVal xmlElement As System.Xml.XmlElement, ByVal context As MindFusion.Diagramming.XmlPersistContext)
        MyBase.LoadFromXml(xmlElement, context)
        MiID = CInt(context.ReadString("ID", xmlElement))
        MsAppTableName = context.ReadString("AppTableName", xmlElement)
        MbHasRTFnote = IIf((context.ReadString("HasRTFnote", xmlElement)).ToUpper = "TRUE", True, False)
    End Sub
    'overrided sub for drawing a table
    Public Overrides Sub Draw(ByVal graphics As MindFusion.Drawing.IGraphics, ByVal options As MindFusion.Diagramming.RenderOptions)
        MyBase.Draw(graphics, options)

        'drawing triangle for table note indication
        If MbHasRTFnote Then DrawNoteTriangle(Me.Bounds, graphics)
    End Sub
    ''overrided sub for drawing handles
    'Public Overrides Sub DrawHandles(ByVal graphics As MindFusion.Drawing.IGraphics, ByVal color As System.Drawing.Color)
    '    Debug.Print("DrawHandles")

    '    Const LdbWidthOfLineForRectangle As Double = 0.5

    '    'drawing filled rectangle for creating new link
    '    Dim LoBrush As System.Drawing.Drawing2D.HatchBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.LightUpwardDiagonal, Drawing.Color.Black, Drawing.Color.LightCoral)
    '    Dim LoRectangleF As RectangleF = New RectangleF(MMRectangleForNewLink.X, MMRectangleForNewLink.Y, MMRectangleForNewLink.Width, MMRectangleForNewLink.Height - IIf(Me.Pen.Width = 0, MindFusion.Diagramming.Constants.GetPixel(Me.Parent.MeasureUnit), Me.Pen.Width) / 2)
    '    graphics.FillRectangle(LoBrush, LoRectangleF)
    '    'drawing rectangle around filled rectangle
    '    Dim LoPen As System.Drawing.Pen = New System.Drawing.Pen(color.Gray, LdbWidthOfLineForRectangle)
    '    LoPen.DashStyle = Drawing2D.DashStyle.Solid
    '    'Dim LoRectangle As Rectangle = New Rectangle(LoRectangleF.X, LoRectangleF.Y, LoRectangleF.Width, LoRectangleF.Height )
    '    LoRectangleF.Height -= IIf(Me.Pen.Width = 0, MindFusion.Diagramming.Constants.GetPixel(Me.Parent.MeasureUnit), Me.Pen.Width) / 2
    '    graphics.DrawRectangles(LoPen, New RectangleF() {LoRectangleF})

    '    'drawing selection rectangle
    '    Const LdbWidthOfLine As Double = 0.7
    '    graphics.DrawRectangle(SDPenVirginCreator(color, LdbWidthOfLine), CType(Me.Bounds.X - LdbWidthOfLine / 2, Single), CType(Me.Bounds.Y - LdbWidthOfLine / 2, Single), CType(Me.Bounds.Width + LdbWidthOfLine, Single), CType(Me.Bounds.Height + LdbWidthOfLine, Single))
    'End Sub
    'overrided sub called after deserialization of node. I can set some properties forcible here!
    Protected Overrides Sub OnLoad()
        MyBase.OnLoad()
    End Sub
#End Region
#Region "MM Subs"
    'default settings of shape
    Public Sub MMSetDefaultProperties()
        'minimum size is connected with minimum size of txtInPlaceEditor used for in-place editing
        Me.Constraints.MinHeight = 10
        Me.Constraints.MinWidth = 20
        'minimum size is connected with minimum size of txtInPlaceEditor used for in-place editing
        Me.Brush = New LinearGradientBrush(Color.White, Color.LightGreen, 90) 'brush is set here. Brush is used to fill the interiors of geometric shapes
        Me.HighlightedRow = -1 'sets the highlighted row to -1 = no row selected
        Me.Obstacle = True ' whether this node is considered an obstacle by the link-routing algorithm
        Me.Bounds = SDRectangleVirginCreator(0, 0, 30, 30)
        Me.EnableStyledText = False 'whether styled text rendering is enabled
        Me.Font = New Font("Arial", 8, FontStyle.Regular) 'font used to draw text inside this cell
        Me.OffsetHeaderRows = True 'whether the table cells are offset to the right to accommodate for the expand buttons of Header rows
        Me.AnchorPattern = CreateAnchorPatternSurrounding(9) 'Represents a set of anchor points, which specify the exact locations where links are allowed to connect to nodes
        Me.Pen = New Pen(Color.Gray) 'pen is used to draw the outline of geometric shapes
        Me.AllowIncomingLinks = True 'true - because of connections between tables and notes
        Me.AllowOutgoingLinks = True 'true - because of connections between tables
        Me.HandlesStyle = HandlesStyle.SquareHandles2  'visual styles for frames that are drawn around selected nodes
        Me.ShadowOffsetX = 0.5 'horizontal offset of the shadow
        Me.ShadowOffsetY = 0.5 'vertical offset of the shadow
        Me.CustomDraw = CustomDraw.Additional 'The custom painting code executes after item's interior and frame are painted by FlowChart.NET, but before text is rendered. In this mode, the Graphics instance passed to the custom drawing event handler has a clipping region applied to it
        Me.Style = TableStyle.RoundedRectangle 'the shape of the table's outline
        Me.ConnectionStyle = TableConnectionStyle.Table 'whether drawing a link from/to this table, should connect a row of the table, or the whole table as single ent
        Me.CellCustomDraw = MindFusion.Diagramming.CustomDraw.Additional 'type of custom drawing performed on the table cells - because I want to handle DrawCell event
        Me.RowHeight = 5 'the default height of table rows
        Me.RowCount = 0 ' the number of rows in the table
        Me.ColumnCount = 6 'the number of columns in the table

        Me.Columns(0).Width = 6
        Me.Columns(0).ColumnStyle = ColumnStyle.FixedWidth 'the manner in which column's width is set.
        Me.Columns(1).ColumnStyle = ColumnStyle.AutoWidth
        Me.Columns(2).Width = 0
        Me.Columns(2).ColumnStyle = ColumnStyle.FixedWidth
        Me.Columns(3).Width = 0
        Me.Columns(3).ColumnStyle = ColumnStyle.FixedWidth
        Me.Columns(4).Width = 0
        Me.Columns(4).ColumnStyle = ColumnStyle.FixedWidth
        Me.Columns(5).Width = 6
        Me.Columns(5).ColumnStyle = ColumnStyle.FixedWidth
        'column #0 - datatype icon
        'column #1 - human column name
        'column #2 - column name
        'column #3 - column ID from xMod DS
        'column #4 - 0 = column doesnt have RTF note, 1 = column has RTF note
        'column #5 - visibility icon

        Me.CellFrameStyle = MindFusion.Diagramming.CellFrameStyle.None 'the style of the cells' frame lines
        Me.ImageAlign = ImageAlign.MiddleRight 'the position and alignment of a picture relative to its destination rectangle
        Me.CaptionHeight = 6 'height of the table's caption area
        Me.CaptionFormat.Alignment = StringAlignment.Center 'alignment and line position of the text used as table caption
        Me.CaptionFormat.FormatFlags = StringFormatFlags.NoClip 'alignment and line position of the text used as table caption
        Me.CaptionFormat.Trimming = StringTrimming.None 'alignment and line position of the text used as table caption
        Me.MsAppTableName = GsStringDefaultValue
        'Me.Caption = "<color=#2E7DA5>" & "<b>" & "Tabulka" & "</b>" & "</color>" 'the text displayed as caption of the table
        Me.Caption = GsStringDefaultValue    'the text displayed as caption of the table
        'Me.Scrollable = True
    End Sub
    'resizes heights of caption, all rows, whole table to fit text inside cells and to fit actual width of table and resizes parent container. Actual width of table is not changed!
    Public Sub MMResizeAllToFitTable(Optional ByVal IbRefreshParentContainer As Boolean = True)
        MMResizeHeightOfCellsToFitText()
        MMResizeHeightOfTableToFitCells()
        If IbRefreshParentContainer Then MMResizeParentContainer()
    End Sub
    'resizes heights of caption and all rows of the table to fit text inside them and to fit actual width of table. Actual width of table is not changed!
    Private Sub MMResizeHeightOfCellsToFitText()
        Dim LnNewHeight As Single
        Dim LnWidth As Single

        'checking Me.Parent for MeasureUnit
        If Me.Parent Is Nothing Then
            Debug.Print("CHYBA!!! - MMResizeHeightOfCellsToFitText - Me.Parent = Nothing")
        End If

        'resizing height of caption
        'maxWidth parameter for MeasureString sub = actual width of caption
        LnWidth = Me.Bounds.Width

        LnNewHeight = Me.Parent.MeasureString(Me.Caption, Me.Font, LnWidth, Me.CaptionFormat).Height

        'setting a new height or keeping minimal height of caption
        Const LnMinimalCaptionHeight As Single = 6
        Me.CaptionHeight = IIf(LnNewHeight > LnMinimalCaptionHeight, LnNewHeight, LnMinimalCaptionHeight)
        'height of table will be at minimum as height of caption + default height of row
        Me.Constraints.MinHeight = Me.CaptionHeight + Me.RowHeight
        'need to set new height right now?
        If Me.Bounds.Height < Me.Constraints.MinHeight Then
            Me.Resize(Me.Bounds.Width, Me.Constraints.MinHeight)
        End If

        'resizing heights of all rows
        'maxWidth parameter for MeasureString sub = actual width of Columns(1)
        LnWidth = Me.Columns(1).Width
        For LiI As Integer = 0 To Me.RowCount - 1
            'calculating new height of row
            LnNewHeight = Me.Parent.MeasureString(Me(1, LiI).Text, Me.Font, LnWidth, Me(1, LiI).TextFormat).Height

            'setting a new height or keeping minimal height of rows (Me.RowHeight)
            Dim LnMinimalRowHeight As Single = Me.RowHeight
            Me.Rows(LiI).Height = IIf(LnNewHeight > LnMinimalRowHeight, LnNewHeight, LnMinimalRowHeight)
        Next
    End Sub
    'resizes height of whole table. Actual width of table is not changed!
    Private Sub MMResizeHeightOfTableToFitCells()
        'checking Me.Parent for MeasureUnit
        If Me.Parent Is Nothing Then
            Debug.Print("CHYBA!!! - MMResizeHeightOfTableToFitCells - Me.Parent =Nothing")
        End If

        Dim LiNewHeight As Integer = Me.CaptionHeight + 3 * IIf(Me.Pen.Width = 0, Constants.GetPixel(Me.Parent.MeasureUnit), Me.Pen.Width)
        '3 is for the top, bottom and caption divider lines. The cell borders should be included in the rows Height and should not add to the height
        For Each LoRow As TableNode.Row In Me.Rows
            LiNewHeight += LoRow.Height
            Me.Resize(Me.Bounds.Width, LiNewHeight)
        Next
    End Sub
    'resizes parent container which table is in
    Public Sub MMResizeParentContainer()
        Dim LoMMContainerNode As ClsMMContainerNode = ContainerNode.GetContainer(Me)
        'If Me.MasterGroup IsNot Nothing AndAlso Me.MasterGroup.MainItem IsNot Nothing AndAlso Me.MasterGroup.MainItem.GetType.Name = "ClsMMContainerNode" Then
        '    CType(Me.MasterGroup.MainItem, ClsMMContainerNode).MMResizeAllToFitContainer()
        If LoMMContainerNode IsNot Nothing Then
            LoMMContainerNode.MMResizeAllToFitContainer()
        End If
    End Sub
    'routes links (depends on parameters - all incoming or all outgoing)
    Public Sub MMRouteLinks(Optional ByVal IbRouteIncomingLinks As Boolean = True, Optional ByVal IbRouteOutgoingLinks As Boolean = True)
        If IbRouteIncomingLinks Then
            For Each LoLink As DiagramLink In IncomingLinks
                LoLink.ReassignAnchorPoints()
            Next
        End If

        If IbRouteOutgoingLinks Then
            For Each LoLink As DiagramLink In OutgoingLinks
                LoLink.ReassignAnchorPoints()
            Next
        End If
    End Sub
    'sets visibility of node for creating new lik
    Public Sub MMSetVisibilityOfNodeForNewLink(ByVal IbValue As Boolean)
        If Me.SubordinateGroup IsNot Nothing Then
            CType(Me.SubordinateGroup.AttachedNodes(0), ClsMMNodeForNewLink).Visible = IbValue
        End If
    End Sub
#End Region
#End Region
#Region "Functions"
#Region "Overrides & Overloads Functions"
    'inserting row to collection of columns and to table
    ' ''Public Overloads Function InsertRow(ByVal IePositionOfNewRow As GePositionOfNewRow, ByVal IiDataType As Integer, ByVal IsNameOfColumn As String, Optional ByVal IiNumberOfPositionOfNewRow As Integer = 0) As GeActionResult
    ' ''    Try
    ' ''        Dim LiPositionOfNewRow As Integer = 0
    ' ''        'what position?
    ' ''        Select Case IePositionOfNewRow
    ' ''            Case GePositionOfNewRow.kkFirst
    ' ''                LiPositionOfNewRow = 0
    ' ''            Case GePositionOfNewRow.kkLast
    ' ''                LiPositionOfNewRow = Me.RowCount
    ' ''            Case GePositionOfNewRow.kkSpecified
    ' ''                LiPositionOfNewRow = IiNumberOfPositionOfNewRow
    ' ''        End Select

    ' ''        If (LiPositionOfNewRow > Me.RowCount) Or (LiPositionOfNewRow < 0) Then
    ' ''            Debug.Print("CHYBA!!! - InsertRow")
    ' ''            Return GeActionResult.kkError
    ' ''        Else
    ' ''            'inserting table column to collection
    ' ''            ' ''If IsInCollection(MoColumns, IoTableColumn.NameOfColumn) Then
    ' ''            ' ''    Return GeActionResult.kkROWOFTABLEDuplicityOfNameOfRow
    ' ''            ' ''Else
    ' ''            ' ''    MoColumns.Add(IoTableColumn, IoTableColumn.NameOfColumn, LiPositionOfNewRow + 1)
    ' ''            ' ''End If

    ' ''            'inserting a new row into table
    ' ''            MyBase.InsertRow(LiPositionOfNewRow)
    ' ''            Me(1, LiPositionOfNewRow).TextFormat.Alignment = StringAlignment.Near
    ' ''            Me(1, LiPositionOfNewRow).TextFormat.FormatFlags = StringFormatFlags.NoClip
    ' ''            Me(1, LiPositionOfNewRow).TextFormat.Trimming = StringTrimming.None
    ' ''            Me(0, LiPositionOfNewRow).Image = frmMainForm.imlTableIcons.Images(IiDataType) 'IoTableColumn.DataType)
    ' ''            Me(1, LiPositionOfNewRow).Text = IsNameOfColumn 'IoTableColumn.NameOfColumn
    ' ''            Return GeActionResult.kkOk
    ' ''        End If
    ' ''    Catch ex As Exception
    ' ''        Return GeActionResult.kkError
    ' ''    End Try
    ' ''End Function
    '' ''deleting row from collection of columns and from table
    ' ''Public Overloads Function DeleteRow(ByVal IiPositionOfDeletedRow As Integer) As GeActionResult
    ' ''    Try
    ' ''        'deleting from collection
    ' ''        MoColumns.Remove(IiPositionOfDeletedRow + 1)
    ' ''        'deleting from table
    ' ''        MyBase.DeleteRow(IiPositionOfDeletedRow)
    ' ''        Return GeActionResult.kkOk
    ' ''    Catch ex As Exception
    ' ''        Return GeActionResult.kkError
    ' ''    End Try
    ' ''End Function
#End Region
#Region "MM Functions"
    'rebuild table (rows of tablenode) based on data from dataset
    Public Function MMRebuildTable(ByVal IoTableRows As DataRow()) As GeActionResult
        Dim LeResult As GeActionResult = GeActionResult.kkError

        Try
            Me.RowCount = 0
            For LiI As Integer = 0 To IoTableRows.Count - 1
                MyBase.InsertRow(LiI)
                Me(0, LiI).ImageAlign = MindFusion.Drawing.ImageAlign.Center
                Me(0, LiI).Image = frmMainForm.imlTableIcons.Images(GetIconNameForTypeOfColumn(IoTableRows(LiI)(KrosLib.Editors.xModDataSet.TableSysnames.DataTable.Columns.DataType))) 'amod2.DsAModOneVersion.TableSysnames.OtherTables.Columns.ColumnType)))

                Me(1, LiI).TextFormat.Alignment = StringAlignment.Near
                Me(1, LiI).TextFormat.FormatFlags = StringFormatFlags.NoClip
                Me(1, LiI).TextFormat.Trimming = StringTrimming.None
                Me(1, LiI).Text = IoTableRows(LiI)(KrosLib.Editors.xModDataSet.TableSysnames.DataTable.Columns.ResValue)

                Me(2, LiI).TextFormat.Alignment = StringAlignment.Near
                Me(2, LiI).TextFormat.FormatFlags = StringFormatFlags.NoClip
                Me(2, LiI).TextFormat.Trimming = StringTrimming.None
                Me(2, LiI).Text = IoTableRows(LiI)(KrosLib.Editors.xModDataSet.TableSysnames.DataTable.Columns.ColumnName)

                Me(3, LiI).Text = IoTableRows(LiI)(KrosLib.Editors.xModDataSet.TableSysnames.DataTable.Columns.Id)

                Me(5, LiI).ImageAlign = MindFusion.Drawing.ImageAlign.Center
                Me(5, LiI).Image = frmMainForm.imlTableIcons.Images(GetVisibilityIconNameForColumn(IoTableRows(LiI)(AMod2.DsAModOneVersion.TableSysnames.OtherTables.Columns.UsedInView)))
            Next

            LeResult = GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            LeResult = GeActionResult.kkError
        End Try

        'resizing table and parent container
        MMResizeAllToFitTable()
        Return LeResult
    End Function
    'gets ColumnName from table row by row index
    Public Function MMGetColumnNameByRowIndex(ByVal IiRowIndex As Integer) As String
        Try
            If IiRowIndex <> -1 Then
                Return Me(2, IiRowIndex).Text
            Else
                Return -1
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'gets row index from by column name
    Public Function MMGeRowIndexByColumnName(ByVal IsColumnName As String) As Integer
        Try
            For LiI As Integer = 0 To Rows.Count - 1
                If Me(2, LiI).Text = IsColumnName Then Return LiI
            Next

            Return -1
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return -1
        End Try
    End Function
    'gets column ID from table row by row index
    Public Function MMGetColumnIDByRowIndex(ByVal IiRowIndex As Integer) As String
        Try
            If IiRowIndex <> -1 Then
                Return Me(3, IiRowIndex).Text
            Else
                Return -1
            End If

        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'gets row index from table by column ID
    Public Function MMGetRowIndexByColumnID(ByVal IiColumnID As Integer) As Integer
        Try
            For LiI As Integer = 0 To Rows.Count - 1
                If Me(3, LiI).Text = IiColumnID.ToString Then Return LiI
            Next

            Return -1
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return -1
        End Try
    End Function
    'gets RTF note indicator of table row
    Public Function MMGetRTFnoteRowIndicator(ByVal IiRowIndex As Integer) As Boolean
        Try
            If IiRowIndex <> -1 Then
                Return IIf(Me(4, IiRowIndex).Text = "1", True, False)
            Else
                Return False
            End If
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return ""
        End Try
    End Function
    'sets RTF note indicator for table row
    Public Function MMSetRTFnoteRowIndicator(ByVal IiRowIndex As Integer, ByVal IbRTFindicator As Boolean) As GeActionResult
        Try
            If IiRowIndex <> -1 Then
                Me(4, IiRowIndex).Text = IIf(IbRTFindicator = True, "1", "0")
            Else
                Return False
            End If
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'sets color of row
    Public Function MMSetRowColor(ByVal IiRow As Integer, ByVal IoBrush As Brush) As GeActionResult
        Try
            For LiI As Integer = 0 To Columns.Count - 1
                Me(LiI, IiRow).Brush = IoBrush
            Next

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'gets collection of relationships links
    Public Function MMGetRelationshipsLinks(ByVal IbIncomingLinks As Boolean) As Collection
        Try
            Dim LoCollection As Collection = New Collection
            Dim LoDiagramLinkCollection As DiagramLinkCollection = IIf(IbIncomingLinks, Me.IncomingLinks, Me.OutgoingLinks)

            For Each LoMMLinkNode As ClsMMLinkNode In LoDiagramLinkCollection
                If LoMMLinkNode.MMTypeOfLink = GeTypeOfLink.kkClassDiagramRelationship Then LoCollection.Add(LoMMLinkNode)
            Next

            Return LoCollection
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'gets number of relationships links specified type (incoming or outgoing)
    Public Function MMGetNumberOfRelationshipsLinks(ByVal IbIncomingLinks As Boolean) As Integer
        Try
            Dim LoDiagramLinkCollection As DiagramLinkCollection = IIf(IbIncomingLinks, Me.IncomingLinks, Me.OutgoingLinks)
            Dim LiResult As Integer = 0

            For Each LoMMLinkNode As ClsMMLinkNode In LoDiagramLinkCollection
                If LoMMLinkNode.MMTypeOfLink = GeTypeOfLink.kkClassDiagramRelationship Then LiResult += 1
            Next

            Return LiResult
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return -1
        End Try
    End Function
#End Region
#End Region

End Class
